home *** CD-ROM | disk | FTP | other *** search
- From: jef@webster.UUCP (Jef Poskanzer)
- Newsgroups: comp.sources.misc
- Subject: v02i083: pbm - Portable Bitmap programs, Part 1/4
- Message-ID: <8803292002.AA24558@webster.sybase.uucp>
- Date: 29 Mar 88 20:02:46 GMT
- Approved: allbery@ncoast.UUCP
-
- comp.sources.misc: Volume 2, Issue 83
- Submitted-By: "Jef Poskanzer" <jef@webster.UUCP>
- Archive-Name: pbm/Part1
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # README
- # FORMATS
- # Makefile
- # cbmtopbm.c
- # cbmtopbm.man
- # icontopbm.c
- # icontopbm.man
- # macptopbm.c
- # macptopbm.man
- # rasttopbm.c
- # rasttopbm.man
- # This archive created: Mon Mar 28 17:20:38 1988
- # By: Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
- export PATH; PATH=/bin:$PATH
- echo shar: extracting "'README'" '(2590 characters)'
- if test -f 'README'
- then
- echo shar: will not over-write existing file "'README'"
- else
- sed 's/^X//' << \SHAR_EOF > 'README'
- X Portable Bitmap Toolkit
- X Distribution of 28mar88
- X Previous distribution 06mar88
- X
- X
- XIncluded are a number of programs for converting various bitmap formats
- Xto and from a portable format; plus some tools for manipulating the
- Xportable bitmaps.
- X
- X
- XFiles in this distribution:
- X
- X README this
- X FORMATS descriptions of the various bitmap formats
- X Makefile guess
- X
- X cbmtopbm.c convert from compact bitmap to portable bitmap
- X icontopbm.c convert from Sun icon to portable bitmap
- X macptopbm.c convert from Macintosh MacPaint to portable bitmap
- X rasttopbm.c convert from Sun raster to portable bitmap
- X xbmtopbm.c convert from X10 or X11 bitmap to portable bitmap
- X xwdtopbm.c convert from X11 window dump file to portable bitmap
- X xxxtopbm.c convert from UNKNOWN BITMAP to portable bitmap
- X
- X pbmtocbm.c convert from portable bitmap to compact bitmap
- X pbmtoicon.c convert from portable bitmap to Sun icon
- X pbmtorast.c convert from portable bitmap to Sun raster
- X pbmtoxbm.c convert from portable bitmap to X11 bitmap
- X pbmtox10bm.c convert from portable bitmap to X10 bitmap
- X pbmtops.c convert from portable bitmap to PostScript
- X pbmtoptx.c convert from portable bitmap to Printronix
- X pbmtoascii.c convert from portable bitmap to ASCII graphic form
- X
- X pbminvert.c invert a portable bitmap
- X pbmcrop.c crop a portable bitmap
- X pbmcatlr.c concatenate portable bitmaps left to right
- X pbmcattb.c concatenate portable bitmaps top to bottom
- X pbmfliplr.c flip a portable bitmap left for right
- X pbmfliptb.c flip a portable bitmap top for bottom
- X pbmtrnspos.c transpose a portable bitmap x for y
- X pbmcut.c cut a rectangle out of a portable bitmap
- X pbmpaste.c paste a rectangle into a portable bitmap
- X pbmenlarge.c enlarge a portable bitmap N times
- X pbmmake.c create a blank bitmap of a specified size
- X
- X libpbm.c a few utility routines
- X pbm.h header file for libpbm
- X bmaliases csh script to make aliases for converting formats
- X *.man manual entries for all of the tools
- X bit_reverse.h useful include file
- X
- X
- XUnpack the files, edit Makefile and change the options to suit,
- Xmake, and enjoy! I've tested this stuff under 4.2 BSD, 4.3 BSD,
- Xand System V rel 2. Nevertheless, I'm sure bugs remain. Feedback
- Xis welcome - send bug reports, enhancements, checks, money orders,
- Xetc. to the addresses below.
- X
- X
- X Jef Poskanzer
- X jef@lbl-rtsg.arpa
- X {ucbvax, lll-crg, sun!pacbell, apple, hplabs}!well!pokey
- X sun!pacbell!sybase!jef
- SHAR_EOF
- if test 2590 -ne "`wc -c < 'README'`"
- then
- echo shar: error transmitting "'README'" '(should have been 2590 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'FORMATS'" '(3173 characters)'
- if test -f 'FORMATS'
- then
- echo shar: will not over-write existing file "'FORMATS'"
- else
- sed 's/^X//' << \SHAR_EOF > 'FORMATS'
- XThe portable bitmap format is a lowest common denominator.
- X
- XFormats currently supported are:
- X
- X X11 and X10 bitmaps
- X X11 window dump files
- X Sun icons
- X Sun raster files.
- X Macintosh MacPaint files
- X PostScript
- X Printronix printer graphics
- X "portable bitmap format"
- X "compact bitmap format"
- X
- X
- XThe portable bitmap format is something I came up with while I was
- Xat Xerox. It is a lowest common denominator. It was originally
- Xdesigned to make it reasonable to mail bitmaps between different
- Xtypes of machines using the typical stupid network mailers we have
- Xtoday. Now it serves as the common language for this family of
- Xbitmap conversion filters. The definition is as follows:
- X
- X - A width, formatted as ASCII characters in decimal.
- X
- X - Whitespace (blanks, TABs, CRs, LFs).
- X
- X - A height, again in ASCII decimal.
- X
- X - Whitespace.
- X
- X - Width * height bits, each either '1' or '0', starting at the top-left
- X corner of the bitmap, proceding in normal English reading order.
- X
- X - The character '1' means black, '0' means white.
- X
- X - Whitespace in the bits section is ignored.
- X
- X - Characters from a "#" to the next end-of-line are ignored (comments).
- X
- X - No line may be longer than 70 characters.
- X
- XHere is an example of a small bitmap in this format:
- X
- X # feep.pbm
- X 24 7
- X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- X 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
- X 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
- X 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
- X 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
- X 0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
- X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- X
- XPrograms that read this format should be as lenient as possible,
- Xaccepting anything that looks remotely like a bitmap. For instance,
- Xthe above example does not actually conform to the standard, since
- Xit has whitespace before the width; neverthless, it should be accepted.
- X
- X
- XThe compact bitmap format is the same basic idea as the portable
- Xformat, but it assumes the underlying filesystem can reliably store
- X8-bit bytes. If you have the compress and zcat programs, you should
- Xnot bother with compact bitmaps -- all formats are about the same size
- Xafter being compressed. Otherwise, compact bitmaps are probably the
- Xmost space-efficient format. The definition:
- X
- X - Two bytes of "magic number", which are always 0x2A 0x17.
- X
- X - Two bytes representing the width. The bytes are in "big-endian"
- X order, i.e. the formula for the width is firstbyte * 256 + secondbyte.
- X
- X - Two bytes representing the height, same order as above.
- X
- X - The bits, in the same order as in the portable format: starting
- X at the top-left, proceeding in normal English reading order.
- X Within each byte, the most significant bit is used first, and so
- X on down to the least significant bit.
- X
- X - Nothing special happens at the end of a row -- no padding, not even
- X to the end of the current byte.
- X
- X - A 1 bit means black, a 0 bit means white;
- X
- X - All eight bits of each byte are used, except of course for the
- X last byte, where there may be some extra bits. These are ignored.
- SHAR_EOF
- if test 3173 -ne "`wc -c < 'FORMATS'`"
- then
- echo shar: error transmitting "'FORMATS'" '(should have been 3173 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Makefile'" '(6287 characters)'
- if test -f 'Makefile'
- then
- echo shar: will not over-write existing file "'Makefile'"
- else
- sed 's/^X//' << \SHAR_EOF > 'Makefile'
- X# Makefile for pbm tools.
- X#
- X# Copyright (C) 1988 by Jef Poskanzer.
- X#
- X# Permission to use, copy, modify, and distribute this software and its
- X# documentation for any purpose and without fee is hereby granted, provided
- X# that the above copyright notice appear in all copies and that both that
- X# copyright notice and this permission notice appear in supporting
- X# documentation. This software is provided "as is" without express or
- X# implied warranty.
- X
- X
- X# Valid options:
- X# OS_BSD Set this if your system is BSD 4.2 or later.
- X# OS_SYSV Set this if your system is System V.
- XOPTIONS = -DOS_BSD
- X
- X
- XCC = cc
- XCFLAGS = -O $(OPTIONS)
- X
- X.SUFFIXES: .man .cat
- X.man.cat:
- X nroff -h -man $< > $@
- X
- X
- Xall: cbmtopbm cbmtopbm.cat icontopbm icontopbm.cat macptopbm \
- X macptopbm.cat rasttopbm rasttopbm.cat xbmtopbm \
- X xbmtopbm.cat xwdtopbm xwdtopbm.cat pbmtocbm pbmtocbm.cat \
- X pbmtoicon pbmtoicon.cat pbmtops pbmtops.cat pbmtoptx \
- X pbmtoptx.cat pbmtorast pbmtorast.cat pbmtoxbm pbmtoxbm.cat \
- X pbmtox10bm pbmtox10bm.cat pbmtoascii pbmtoascii.cat pbmcatlr \
- X pbmcatlr.cat pbmcattb pbmcattb.cat pbmfliplr pbmfliplr.cat \
- X pbmfliptb pbmfliptb.cat pbminvert pbminvert.cat pbmcrop \
- X pbmcrop.cat pbmtrnspos pbmtrnspos.cat pbmcut pbmcut.cat \
- X pbmpaste pbmpaste.cat xxxtopbm xxxtopbm.cat pbmenlarge \
- X pbmenlarge.cat pbmmake pbmmake.cat pbm.cat
- X
- X
- Xcbmtopbm: cbmtopbm.o libpbm.a
- X $(CC) -s -o cbmtopbm cbmtopbm.o libpbm.a
- X
- Xcbmtopbm.o: cbmtopbm.c pbm.h
- X
- X
- Xicontopbm: icontopbm.o libpbm.a
- X $(CC) -s -o icontopbm icontopbm.o libpbm.a
- X
- Xicontopbm.o: icontopbm.c pbm.h
- X
- X
- Xmacptopbm: macptopbm.o libpbm.a
- X $(CC) -s -o macptopbm macptopbm.o libpbm.a
- X
- Xmacptopbm.o: macptopbm.c pbm.h
- X
- X
- Xrasttopbm: rasttopbm.o libpbm.a
- X $(CC) -s -o rasttopbm rasttopbm.o libpbm.a -lpixrect
- X
- Xrasttopbm.o: rasttopbm.c pbm.h
- X
- X
- Xxxxtopbm: xxxtopbm.o libpbm.a
- X $(CC) -s -o xxxtopbm xxxtopbm.o libpbm.a
- X
- Xxxxtopbm.o: xxxtopbm.c pbm.h
- X
- X
- Xpbmcatlr: pbmcatlr.o libpbm.a
- X $(CC) -s -o pbmcatlr pbmcatlr.o libpbm.a
- X
- Xpbmcatlr.o: pbmcatlr.c pbm.h
- X
- X
- Xpbmcattb: pbmcattb.o libpbm.a
- X $(CC) -s -o pbmcattb pbmcattb.o libpbm.a
- X
- Xpbmcattb.o: pbmcattb.c pbm.h
- X
- X
- Xpbmfliplr: pbmfliplr.o libpbm.a
- X $(CC) -s -o pbmfliplr pbmfliplr.o libpbm.a
- X
- Xpbmfliplr.o: pbmfliplr.c pbm.h
- X
- X
- Xpbmfliptb: pbmfliptb.o libpbm.a
- X $(CC) -s -o pbmfliptb pbmfliptb.o libpbm.a
- X
- Xpbmfliptb.o: pbmfliptb.c pbm.h
- X
- X
- Xpbminvert: pbminvert.o libpbm.a
- X $(CC) -s -o pbminvert pbminvert.o libpbm.a
- X
- Xpbminvert.o: pbminvert.c pbm.h
- X
- X
- Xpbmcrop: pbmcrop.o libpbm.a
- X $(CC) -s -o pbmcrop pbmcrop.o libpbm.a
- X
- Xpbmcrop.o: pbmcrop.c pbm.h
- X
- X
- Xpbmtrnspos: pbmtrnspos.o libpbm.a
- X $(CC) -s -o pbmtrnspos pbmtrnspos.o libpbm.a
- X
- Xpbmtrnspos.o: pbmtrnspos.c pbm.h
- X
- X
- Xpbmcut: pbmcut.o libpbm.a
- X $(CC) -s -o pbmcut pbmcut.o libpbm.a
- X
- Xpbmcut.o: pbmcut.c pbm.h
- X
- X
- Xpbmpaste: pbmpaste.o libpbm.a
- X $(CC) -s -o pbmpaste pbmpaste.o libpbm.a
- X
- Xpbmpaste.o: pbmpaste.c pbm.h
- X
- X
- Xpbmenlarge: pbmenlarge.o libpbm.a
- X $(CC) -s -o pbmenlarge pbmenlarge.o libpbm.a
- X
- Xpbmenlarge.o: pbmenlarge.c pbm.h
- X
- X
- Xpbmmake: pbmmake.o libpbm.a
- X $(CC) -s -o pbmmake pbmmake.o libpbm.a
- X
- Xpbmmake.o: pbmmake.c pbm.h
- X
- X
- Xpbmtocbm: pbmtocbm.o libpbm.a
- X $(CC) -s -o pbmtocbm pbmtocbm.o libpbm.a
- X
- Xpbmtocbm.o: pbmtocbm.c pbm.h
- X
- X
- Xpbmtoicon: pbmtoicon.o libpbm.a
- X $(CC) -s -o pbmtoicon pbmtoicon.o libpbm.a
- X
- Xpbmtoicon.o: pbmtoicon.c pbm.h
- X
- X
- Xpbmtops: pbmtops.o libpbm.a
- X $(CC) -s -o pbmtops pbmtops.o libpbm.a
- X
- Xpbmtops.o: pbmtops.c pbm.h
- X
- X
- Xpbmtoptx: pbmtoptx.o libpbm.a
- X $(CC) -s -o pbmtoptx pbmtoptx.o libpbm.a
- X
- Xpbmtoptx.o: pbmtoptx.c pbm.h
- X
- X
- Xpbmtorast: pbmtorast.o libpbm.a
- X $(CC) -s -o pbmtorast pbmtorast.o libpbm.a -lpixrect
- X
- Xpbmtorast.o: pbmtorast.c pbm.h
- X
- X
- Xpbmtoxbm: pbmtoxbm.o libpbm.a
- X $(CC) -s -o pbmtoxbm pbmtoxbm.o libpbm.a
- X
- Xpbmtoxbm.o: pbmtoxbm.c pbm.h
- X
- X
- Xpbmtox10bm: pbmtox10bm.o libpbm.a
- X $(CC) -s -o pbmtox10bm pbmtox10bm.o libpbm.a
- X
- Xpbmtox10bm.o: pbmtox10bm.c pbm.h
- X
- X
- Xpbmtoascii: pbmtoascii.o libpbm.a
- X $(CC) -s -o pbmtoascii pbmtoascii.o libpbm.a
- X
- Xpbmtoascii.o: pbmtoascii.c pbm.h
- X
- X
- Xxbmtopbm: xbmtopbm.o libpbm.a
- X $(CC) -s -o xbmtopbm xbmtopbm.o libpbm.a
- X
- Xxbmtopbm.o: xbmtopbm.c pbm.h
- X
- X
- Xxwdtopbm: xwdtopbm.o libpbm.a
- X $(CC) -s -o xwdtopbm xwdtopbm.o libpbm.a
- X
- Xxwdtopbm.o: xwdtopbm.c pbm.h
- X
- X
- Xlibpbm.a: libpbm.o
- X ar r libpbm.a libpbm.o
- X -ranlib libpbm.a
- X
- Xlibpbm.o: libpbm.c pbm.h
- X
- X
- Xclean:
- X -rm -f *.o libpbm.a *.cat pbm.shar* core icontopbm
- X -rm -f macptopbm rasttopbm pbmcatlr pbmcattb pbmcrop
- X -rm -f pbmfliplr pbmfliptb pbminvert pbmtoicon pbmtops
- X -rm -f pvmtoptx pbmtorast pbmtoxbm pbmtox10bm xbmtopbm
- X -rm -f xwdtopbm pbmtoascii pbmtocbm cbmtopbm pbmtrnspos
- X -rm -f pbmcut pbmpaste pbmenlarge pbmmake xxxtopbm
- X
- X
- Xshar: pbm.shar1 pbm.shar2 pbm.shar3 pbm.shar4
- X
- Xpbm.shar1: README FORMATS Makefile cbmtopbm.c cbmtopbm.man icontopbm.c \
- X icontopbm.man macptopbm.c macptopbm.man rasttopbm.c \
- X rasttopbm.man
- X shar -v -c -p X README FORMATS Makefile cbmtopbm.c cbmtopbm.man icontopbm.c icontopbm.man macptopbm.c macptopbm.man rasttopbm.c rasttopbm.man > pbm.shar1
- X
- Xpbm.shar2: xbmtopbm.c xbmtopbm.man xwdtopbm.c xwdtopbm.man pbmtocbm.c \
- X pbmtocbm.man pbmtoicon.c pbmtoicon.man pbmtops.c pbmtops.man \
- X pbmtoptx.c pbmtoptx.man pbmtorast.c pbmtorast.man
- X shar -v -c -p X xbmtopbm.c xbmtopbm.man xwdtopbm.c xwdtopbm.man pbmtocbm.c pbmtocbm.man pbmtoicon.c pbmtoicon.man pbmtops.c pbmtops.man pbmtoptx.c pbmtoptx.man pbmtorast.c pbmtorast.man > pbm.shar2
- X
- Xpbm.shar3: pbmtoxbm.c pbmtoxbm.man pbmtox10bm.c pbmtox10bm.man \
- X pbmtoascii.c pbmtoascii.man pbmcatlr.c pbmcatlr.man pbmcattb.c \
- X pbmcattb.man pbmfliplr.c pbmfliplr.man pbmfliptb.c \
- X pbmfliptb.man pbminvert.c pbminvert.man
- X shar -v -c -p X pbmtoxbm.c pbmtoxbm.man pbmtox10bm.c pbmtox10bm.man pbmtoascii.c pbmtoascii.man pbmcatlr.c pbmcatlr.man pbmcattb.c pbmcattb.man pbmfliplr.c pbmfliplr.man pbmfliptb.c pbmfliptb.man pbminvert.c pbminvert.man > pbm.shar3
- X
- Xpbm.shar4: pbmcrop.c pbmcrop.man pbmtrnspos.c pbmtrnspos.man pbmcut.c \
- X pbmcut.man pbmpaste.c pbmpaste.man xxxtopbm.c xxxtopbm.man \
- X pbmenlarge.c pbmenlarge.man pbmmake.c pbmmake.man libpbm.c \
- X pbm.h pbm.man bmaliases bit_reverse.h
- X shar -v -c -p X pbmcrop.c pbmcrop.man pbmtrnspos.c pbmtrnspos.man pbmcut.c pbmcut.man pbmpaste.c pbmpaste.man xxxtopbm.c xxxtopbm.man pbmenlarge.c pbmenlarge.man pbmmake.c pbmmake.man libpbm.c pbm.h pbm.man bmaliases bit_reverse.h > pbm.shar4
- SHAR_EOF
- if test 6287 -ne "`wc -c < 'Makefile'`"
- then
- echo shar: error transmitting "'Makefile'" '(should have been 6287 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'cbmtopbm.c'" '(1923 characters)'
- if test -f 'cbmtopbm.c'
- then
- echo shar: will not over-write existing file "'cbmtopbm.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.c'
- X/* cbmtopbm.c - read a compact bitmap and write a portable bitmap
- X**
- X** Copyright (C) 1988 by Jef Poskanzer.
- X**
- X** Permission to use, copy, modify, and distribute this software and its
- X** documentation for any purpose and without fee is hereby granted, provided
- X** that the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. This software is provided "as is" without express or
- X** implied warranty.
- X*/
- X
- X#include <stdio.h>
- X#include "pbm.h"
- X
- Xmain( argc, argv )
- Xint argc;
- Xchar *argv[];
- X {
- X FILE *ifd;
- X bit **bits, getbit();
- X int rows, cols, row, col;
- X
- X if ( argc > 2 )
- X {
- X fprintf( stderr, "usage: %s [cbmfile]\n", argv[0] );
- X exit( 1 );
- X }
- X
- X if ( argc == 2 )
- X {
- X ifd = fopen( argv[1], "r" );
- X if ( ifd == NULL )
- X {
- X fprintf( stderr, "%s: can't open.\n", argv[1] );
- X exit( 1 );
- X }
- X }
- X else
- X ifd = stdin;
- X
- X getinit( ifd, &cols, &rows );
- X
- X bits = pbm_allocarray( cols, rows );
- X
- X for ( row = 0; row < rows; row++ )
- X for ( col = 0; col < cols; col++ )
- X bits[row][col] = getbit( ifd );
- X
- X if ( ifd != stdin )
- X fclose( ifd );
- X
- X pbm_writepbm( stdout, bits, cols, rows );
- X
- X exit( 0 );
- X }
- X
- X
- Xint item, bitsperitem, bitshift;
- X
- Xgetinit( file, colp, rowp )
- XFILE *file;
- Xint *colp, *rowp;
- X {
- X if ( getc( file ) != 42 )
- X {
- X fprintf( stderr, "Bad magic number 1.\n" );
- X exit( 1 );
- X }
- X if ( getc( file ) != 23 )
- X {
- X fprintf( stderr, "Bad magic number 2.\n" );
- X exit( 1 );
- X }
- X *colp = getc( file ) << 8;
- X *colp += getc( file );
- X *rowp = getc( file ) << 8;
- X *rowp += getc( file );
- X bitsperitem = 8;
- X }
- X
- Xbit
- Xgetbit( file )
- XFILE *file;
- X {
- X bit b;
- X
- X if ( bitsperitem == 8 )
- X {
- X item = getc( file );
- X bitsperitem = 0;
- X bitshift = 7;
- X }
- X bitsperitem++;
- X b = ( item >> bitshift) & 1;
- X bitshift--;
- X return ( b );
- X }
- SHAR_EOF
- if test 1923 -ne "`wc -c < 'cbmtopbm.c'`"
- then
- echo shar: error transmitting "'cbmtopbm.c'" '(should have been 1923 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'cbmtopbm.man'" '(969 characters)'
- if test -f 'cbmtopbm.man'
- then
- echo shar: will not over-write existing file "'cbmtopbm.man'"
- else
- sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.man'
- X.TH cbmtopbm 1 "13 February 1988"
- X.SH NAME
- Xcbmtopbm - convert compact bitmaps into portable bitmaps
- X.SH SYNOPSIS
- Xcbmtopbm [cbmfile]
- X.SH DESCRIPTION
- XReads a compact bitmap as input.
- XProduces a portable bitmap as output.
- X.SH "SEE ALSO"
- Xpbm(5), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
- Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
- Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
- Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
- Xpbmpaste(1), pbmenlarge(1)
- X.SH AUTHOR
- XCopyright (C) 1988 by Jef Poskanzer.
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted, provided
- Xthat the above copyright notice appear in all copies and that both that
- Xcopyright notice and this permission notice appear in supporting
- Xdocumentation. This software is provided "as is" without express or
- Ximplied warranty.
- SHAR_EOF
- if test 969 -ne "`wc -c < 'cbmtopbm.man'`"
- then
- echo shar: error transmitting "'cbmtopbm.man'" '(should have been 969 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'icontopbm.c'" '(4272 characters)'
- if test -f 'icontopbm.c'
- then
- echo shar: will not over-write existing file "'icontopbm.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'icontopbm.c'
- X/* icontopbm.c - read a Sun icon file and produce a portable bitmap
- X**
- X** Copyright (C) 1988 by Jef Poskanzer.
- X**
- X** Permission to use, copy, modify, and distribute this software and its
- X** documentation for any purpose and without fee is hereby granted, provided
- X** that the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. This software is provided "as is" without express or
- X** implied warranty.
- X*/
- X
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include "pbm.h"
- X
- Xmain( argc, argv )
- Xint argc;
- Xchar *argv[];
- X {
- X FILE *ifd;
- X bit **bits;
- X int rows, cols, row, col, shortcount, mask;
- X short *data;
- X
- X if ( argc > 2 )
- X {
- X fprintf( stderr, "usage: %s [iconfile]\n", argv[0] );
- X exit( 1 );
- X }
- X
- X if ( argc == 2 )
- X {
- X ifd = fopen( argv[1], "r" );
- X if ( ifd == NULL )
- X {
- X fprintf( stderr, "%s: can't open.\n", argv[1] );
- X exit( 1 );
- X }
- X }
- X else
- X ifd = stdin;
- X
- X if ( ReadIconFile( ifd, &cols, &rows, &data ) < 0 )
- X {
- X fprintf( stderr, "%s: can't load.\n", argv[1] );
- X exit( 1 );
- X }
- X
- X if ( ifd != stdin )
- X fclose( ifd );
- X
- X bits = pbm_allocarray( cols, rows );
- X
- X for ( row = 0; row < rows; row++ )
- X {
- X shortcount = 0;
- X mask = 0x8000;
- X for ( col = 0; col < cols; col++ )
- X {
- X if ( shortcount >= 16 )
- X {
- X data++;
- X shortcount = 0;
- X mask = 0x8000;
- X }
- X bits[row][col] = ( ( *data & mask ) ? 1 : 0 );
- X shortcount++;
- X mask = mask >> 1;
- X }
- X data++;
- X }
- X
- X pbm_writepbm( stdout, bits, cols, rows );
- X
- X exit( 0 );
- X }
- X
- X
- X/* size in bytes of a bitmap */
- X#define BitmapSize(width, height) (((((width) + 15) >> 3) &~ 1) * (height))
- X
- Xint
- XReadIconFile( file, width, height, data )
- XFILE *file;
- Xint *width, *height;
- Xshort **data;
- X {
- X char variable[81], ch;
- X int status, firsttime, value, i, data_length;
- X
- X if ( file == NULL )
- X return ( -1 );
- X
- X if ( getc( file ) != '/' )
- X {
- X fprintf( stderr, "Error 1 scanning beginning of initial section.\n" );
- X return ( -1 );
- X }
- X if ( getc( file ) != '*' )
- X {
- X fprintf( stderr, "Error 2 scanning beginning of initial section.\n" );
- X return ( -1 );
- X }
- X while ( ( ch = getc( file ) ) == '\n' | ch == '\t' | ch == ' ' )
- X ;
- X ungetc( ch, stdin );
- X
- X *width = *height = -1;
- X firsttime = -1;
- X for ( ; ; )
- X {
- X if ( firsttime )
- X firsttime = 0;
- X else
- X if ( getc( file ) != ',' )
- X break;
- X while ( ( ch = getc( file ) ) == '\n' | ch == '\t' | ch == ' ' )
- X ;
- X for ( i = 0; ch != '='; i++ )
- X {
- X variable[i] = ch;
- X ch = getc( file );
- X }
- X variable[i] = '\0';
- X
- X if ( fscanf( file, "%d", &value ) != 1 )
- X break;
- X
- X if ( strcmp( variable, "Width" ) == 0 )
- X *width = value;
- X else if ( strcmp( variable, "Height" ) == 0 )
- X *height = value;
- X else if ( strcmp( variable, "Depth" ) == 0 )
- X {
- X if ( value != 1 )
- X {
- X fprintf( stderr, "Invalid depth.\n" );
- X return ( -1 );
- X }
- X }
- X else if ( strcmp( variable, "Format_version" ) == 0 )
- X {
- X if ( value != 1 )
- X {
- X fprintf( stderr, "Invalid Format_version.\n" );
- X return ( -1 );
- X }
- X }
- X else if ( strcmp( variable, "Valid_bits_per_item" ) == 0 )
- X {
- X if ( value != 16 )
- X {
- X fprintf( stderr, "Invalid Valid_bits_per_item.\n" );
- X return ( -1 );
- X }
- X }
- X }
- X
- X for ( ; ; )
- X {
- X while ( getc( file ) != '*' )
- X ;
- X if ( ( ch = getc( file ) ) == '/' )
- X break;
- X ungetc( ch, stdin );
- X }
- X if ( getc( file ) != '\n' )
- X {
- X fprintf( stderr, "Error 3 scanning end of initial section.\n" );
- X return ( -1 );
- X }
- X
- X if ( *width <= 0 )
- X {
- X fprintf( stderr, "Invalid width: %d.\n", *width );
- X return ( -1 );
- X }
- X
- X if ( *height <= 0 )
- X {
- X fprintf( stderr, "Invalid height: %d.\n", *height );
- X return ( -1 );
- X }
- X
- X data_length = BitmapSize( *width, *height );
- X *data = (short *) malloc( data_length );
- X data_length /= sizeof( short );
- X if ( *data == NULL )
- X {
- X return ( -1 );
- X }
- X
- X for ( i = 0 ; i < data_length; i++ )
- X {
- X if ( i == 0 )
- X status = fscanf( file, " 0x%4hx", *data );
- X else
- X status = fscanf( file, ", 0x%4hx", *data + i );
- X if ( status != 1 )
- X {
- X free( *data );
- X fprintf( stderr, "Error 4 scanning bits item.\n" );
- X return ( -1 );
- X }
- X }
- X
- X return ( 0 );
- X }
- SHAR_EOF
- if test 4272 -ne "`wc -c < 'icontopbm.c'`"
- then
- echo shar: error transmitting "'icontopbm.c'" '(should have been 4272 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'icontopbm.man'" '(960 characters)'
- if test -f 'icontopbm.man'
- then
- echo shar: will not over-write existing file "'icontopbm.man'"
- else
- sed 's/^X//' << \SHAR_EOF > 'icontopbm.man'
- X.TH icontopbm 1 "13 February 1988"
- X.SH NAME
- Xicontopbm - convert Sun icons into portable bitmaps
- X.SH SYNOPSIS
- Xicontopbm [iconfile]
- X.SH DESCRIPTION
- XReads a Sun icon as input.
- XProduces a portable bitmap as output.
- X.SH "SEE ALSO"
- Xpbm(5), cbmtopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
- Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
- Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
- Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
- Xpbmpaste(1), pbmenlarge(1)
- X.SH AUTHOR
- XCopyright (C) 1988 by Jef Poskanzer.
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted, provided
- Xthat the above copyright notice appear in all copies and that both that
- Xcopyright notice and this permission notice appear in supporting
- Xdocumentation. This software is provided "as is" without express or
- Ximplied warranty.
- SHAR_EOF
- if test 960 -ne "`wc -c < 'icontopbm.man'`"
- then
- echo shar: error transmitting "'icontopbm.man'" '(should have been 960 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'macptopbm.c'" '(3073 characters)'
- if test -f 'macptopbm.c'
- then
- echo shar: will not over-write existing file "'macptopbm.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'macptopbm.c'
- X/* macptopbm.c - read a Macintosh MacPaint file and produce a portable bitmap
- X**
- X** Copyright (C) 1988 by Jef Poskanzer.
- X**
- X** Permission to use, copy, modify, and distribute this software and its
- X** documentation for any purpose and without fee is hereby granted, provided
- X** that the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. This software is provided "as is" without express or
- X** implied warranty.
- X*/
- X
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include "pbm.h"
- X
- X#define BORDER_WIDTH 3
- X#define HEADER_LENGTH 0x280
- X#define MAX_LINES 720
- X#define BYTES_WIDE 72
- X#define MAX_NAME 64
- X
- Xmain( argc, argv )
- Xint argc;
- Xchar *argv[];
- X {
- X FILE *ifd;
- X unsigned char Pic[MAX_LINES][BYTES_WIDE];
- X bit **bits;
- X int scanLine, rows, cols, row, bcol, i;
- X
- X if ( argc > 2 )
- X {
- X fprintf( stderr, "usage: %s [macpfile]\n", argv[0] );
- X exit( 1 );
- X }
- X
- X if ( argc == 2 )
- X {
- X ifd = fopen( argv[1], "r" );
- X if ( ifd == NULL )
- X {
- X fprintf( stderr, "%s: can't open.\n", argv[1] );
- X exit( 1 );
- X }
- X }
- X else
- X ifd = stdin;
- X
- X if ( ReadMacPaintFile( ifd, &scanLine, Pic ) < 0 )
- X {
- X fprintf( stderr, "%s: can't load.\n", argv[1] );
- X exit( 1 );
- X }
- X
- X if ( ifd != stdin )
- X fclose( ifd );
- X
- X cols = BYTES_WIDE * 8;
- X rows = scanLine;
- X bits = pbm_allocarray( cols, rows );
- X
- X for ( row = 0; row < rows; row++ )
- X for ( bcol = 0; bcol < BYTES_WIDE; bcol++ )
- X for ( i = 0; i < 8; i++ )
- X bits[row][bcol * 8 + i] = ( (Pic[row][bcol] >> (7 - i)) & 1);
- X
- X pbm_writepbm( stdout, bits, cols, rows );
- X
- X exit( 0 );
- X }
- X
- X/*
- X** Some of the following routine is:
- X**
- X** Copyright 1987 by Patrick J. Naughton
- X** All Rights Reserved
- X** Permission to use, copy, modify, and distribute this software and its
- X** documentation for any purpose and without fee is hereby granted,
- X** provided that the above copyright notice appear in all copies and that
- X** both that copyright notice and this permission notice appear in
- X** supporting documentation.
- X*/
- X
- Xint
- XReadMacPaintFile( file, scanLineP, Pic )
- XFILE *file;
- Xint *scanLineP;
- Xunsigned char Pic[MAX_LINES][BYTES_WIDE];
- X {
- X unsigned int i, j, k;
- X unsigned char ch;
- X
- X /* Skip over the header. */
- X for ( i = 0; i < HEADER_LENGTH; i++ )
- X getc( file );
- X
- X *scanLineP = 0;
- X k = 0;
- X
- X while ( *scanLineP < MAX_LINES )
- X {
- X ch = (unsigned char) getc( file ); /* Count byte */
- X i = (unsigned int) ch;
- X if ( ch < 0x80 )
- X { /* Unpack next (I+1) chars as is */
- X for ( j = 0; j <= i; j++ )
- X if ( *scanLineP < MAX_LINES )
- X {
- X Pic[*scanLineP][k++] = (unsigned char) getc( file );
- X if ( ! (k %= BYTES_WIDE) )
- X *scanLineP += 1;
- X }
- X }
- X else
- X { /* Repeat next char (2's comp I) times */
- X ch = getc( file );
- X for ( j = 0; j <= 256 - i; j++ )
- X if ( *scanLineP < MAX_LINES )
- X {
- X Pic[*scanLineP][k++] = (unsigned char) ch;
- X if ( ! (k %= BYTES_WIDE) )
- X *scanLineP += 1;
- X }
- X }
- X }
- X
- X return(0);
- X }
- SHAR_EOF
- if test 3073 -ne "`wc -c < 'macptopbm.c'`"
- then
- echo shar: error transmitting "'macptopbm.c'" '(should have been 3073 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'macptopbm.man'" '(1452 characters)'
- if test -f 'macptopbm.man'
- then
- echo shar: will not over-write existing file "'macptopbm.man'"
- else
- sed 's/^X//' << \SHAR_EOF > 'macptopbm.man'
- X.TH macptopbm 1 "13 February 1988"
- X.SH NAME
- Xmacptopbm - convert Macintosh MacPaint files into portable bitmaps
- X.SH SYNOPSIS
- Xmacptopbm [macpfile]
- X.SH DESCRIPTION
- XReads a Macintosh MacPaint file as input.
- XProduces a portable bitmap as output.
- X.LP
- XNote that there is currently no pbmtomacp tool.
- X.SH "SEE ALSO"
- Xpbm(5), cbmtopbm(1), icontopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
- Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
- Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
- Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
- Xpbmpaste(1), pbmenlarge(1)
- X.SH AUTHOR
- XCopyright (C) 1988 by Jef Poskanzer.
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted, provided
- Xthat the above copyright notice appear in all copies and that both that
- Xcopyright notice and this permission notice appear in supporting
- Xdocumentation. This software is provided "as is" without express or
- Ximplied warranty.
- X
- XThe MacPaint-reading code is
- X Copyright (c) 1987 by Patrick J. Naughton,
- X (naughton@sun.soe.clarkson.edu)
- X
- X Permission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted,
- Xprovided that the above copyright notice appear in all copies and that
- Xboth that copyright notice and this permission notice appear in
- Xsupporting documentation.
- SHAR_EOF
- if test 1452 -ne "`wc -c < 'macptopbm.man'`"
- then
- echo shar: error transmitting "'macptopbm.man'" '(should have been 1452 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'rasttopbm.c'" '(3255 characters)'
- if test -f 'rasttopbm.c'
- then
- echo shar: will not over-write existing file "'rasttopbm.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'rasttopbm.c'
- X/* rasttopbm.c - read a Sun raster file and produce a portable bitmap
- X**
- X** Copyright (C) 1988 by Jef Poskanzer.
- X**
- X** Permission to use, copy, modify, and distribute this software and its
- X** documentation for any purpose and without fee is hereby granted, provided
- X** that the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. This software is provided "as is" without express or
- X** implied warranty.
- X*/
- X
- X#include <stdio.h>
- X#include "pbm.h"
- X
- X/* Because of the following include, this program compiles only on Suns. */
- X#include <pixrect/pixrect_hs.h>
- X
- Xmain( argc, argv )
- Xint argc;
- Xchar *argv[];
- X {
- X FILE *ifd;
- X bit **bits;
- X int rows, cols, row, col, shortcount, mask;
- X int linesize;
- X short *data;
- X
- X if ( argc > 2 )
- X {
- X fprintf( stderr, "usage: %s [rastfile]\n", argv[0] );
- X exit( 1 );
- X }
- X
- X if ( argc == 2 )
- X {
- X ifd = fopen( argv[1], "r" );
- X if ( ifd == NULL )
- X {
- X fprintf( stderr, "%s: can't open.\n", argv[1] );
- X exit( 1 );
- X }
- X }
- X else
- X ifd = stdin;
- X
- X if ( ReadRasterFile( ifd, &cols, &rows, &linesize, &data ) < 0 )
- X {
- X fprintf( stderr, "%s: can't load.\n", argv[1] );
- X exit( 1 );
- X }
- X
- X if ( ifd != stdin )
- X fclose( ifd );
- X
- X bits = pbm_allocarray( cols, rows );
- X
- X for ( row = 0; row < rows; row++ )
- X {
- X shortcount = 0;
- X mask = 0x8000;
- X for ( col = 0; col < cols; col++ )
- X {
- X if ( mask == 0 )
- X {
- X shortcount++;
- X mask = 0x8000;
- X }
- X bits[row][col] = ( *(data + shortcount) & mask ) ? 1 : 0;
- X mask = mask >> 1;
- X }
- X data += linesize / sizeof(short);
- X }
- X
- X pbm_writepbm( stdout, bits, cols, rows );
- X
- X exit( 0 );
- X }
- X
- X
- Xint
- XReadRasterFile( file, width, height, linebytes, data )
- XFILE *file;
- Xint *width, *height;
- Xint *linebytes;
- Xshort **data;
- X {
- X struct rasterfile header;
- X struct pixrect *pr, *pr_load_image();
- X int status, firsttime, value, i, data_length;
- X
- X if ( file == NULL )
- X return ( -1 );
- X
- X *width = *height = -1;
- X
- X
- X /* Get the raster file's header. */
- X if ( pr_load_header( file, &header ) != 0 )
- X {
- X fprintf( stderr, "Unable to read in raster file header.\n");
- X return ( -1 );
- X }
- X
- X /* PBM can only handle monochrome bitmaps. */
- X if ( header.ras_depth != 1 )
- X {
- X fprintf( stderr, "Invalid depth.\n" );
- X return ( -1 );
- X }
- X
- X *width = header.ras_width;
- X *height = header.ras_height;
- X if ( *width <= 0 )
- X {
- X fprintf( stderr, "Invalid width: %d.\n", *width );
- X return ( -1 );
- X }
- X
- X if ( *height <= 0 )
- X {
- X fprintf( stderr, "Invalid height: %d.\n", *height );
- X return ( -1 );
- X }
- X
- X /* If there is a color map, skip over it. */
- X if ( header.ras_maptype != RMT_NONE && header.ras_maplength != 0 )
- X {
- X if (pr_load_colormap(file, &header, NULL) != 0)
- X {
- X fprintf( stderr, "Unable to skip colormap data.\n");
- X return ( -1 );
- X }
- X }
- X
- X /* Now load the data. The pixrect returned is a memory pixrect. */
- X if ( (pr = pr_load_image(file, &header, NULL)) == NULL )
- X {
- X fprintf(
- X stderr, "Unable to read in the image from the raster file.\n");
- X return ( -1 );
- X }
- X
- X *linebytes = ((struct mpr_data *)pr->pr_data)->md_linebytes;
- X *data = ((struct mpr_data *)pr->pr_data)->md_image;
- X
- X return ( 0 );
- X }
- SHAR_EOF
- if test 3255 -ne "`wc -c < 'rasttopbm.c'`"
- then
- echo shar: error transmitting "'rasttopbm.c'" '(should have been 3255 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'rasttopbm.man'" '(1350 characters)'
- if test -f 'rasttopbm.man'
- then
- echo shar: will not over-write existing file "'rasttopbm.man'"
- else
- sed 's/^X//' << \SHAR_EOF > 'rasttopbm.man'
- X.TH rasttopbm 1 "18 February 1988"
- X.SH NAME
- Xrasttopbm - convert Sun rasters into portable bitmaps
- X.SH SYNOPSIS
- Xrasttopbm [rastfile]
- X.SH DESCRIPTION
- XReads a Sun raster as input.
- XProduces a portable bitmap as output.
- XNOTE: since it uses Sun-specific include files, pbmtorast will compile
- Xonly on Suns.
- X.LP
- XUsing this program you can convert anything you can see on a Sun screen
- Xinto a pbm bitmap.
- XJust display whatever you're interested in, do a screendump, run it through
- Xrasfilter8to1 if you're on a color Sun, run it through rasttopbm, and then
- Xuse pbmcut to select the part you want.
- X.SH "SEE ALSO"
- Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), xbmtopbm(1), xwdtopbm(1),
- Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
- Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
- Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
- Xpbmpaste(1), pbmenlarge(1)
- X.SH AUTHOR
- XBarry Klawans
- X
- XCopyright (C) 1988 by Jef Poskanzer.
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted, provided
- Xthat the above copyright notice appear in all copies and that both that
- Xcopyright notice and this permission notice appear in supporting
- Xdocumentation. This software is provided "as is" without express or
- Ximplied warranty.
- SHAR_EOF
- if test 1350 -ne "`wc -c < 'rasttopbm.man'`"
- then
- echo shar: error transmitting "'rasttopbm.man'" '(should have been 1350 characters)'
- fi
- fi # end of overwriting check
- # End of shell archive
- exit 0
-